package com.springboot.springbootlogindemo.controller;

import com.springboot.springbootlogindemo.service.LikeService;
import com.springboot.springbootlogindemo.utils.Result;
import com.springboot.springbootlogindemo.utils.UserHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/likes")
public class LikeController {

    @Resource
    private LikeService likeService; // 引入服务层接口

    /**
     * 点赞操作
     *
     * @param infoId     被点赞的内容 ID
     * @return 操作结果
     */
    @PostMapping("/like")
    public Result like(@RequestParam String infoId) {
        return likeService.like(infoId,UserHolder.getUser().getId().toString());
    }


    /**
     * 用于查找点赞记录信息
     * @param infoId
     * @return
     */
    @GetMapping("/record")
    public Result record(@RequestParam String infoId){
        return likeService.record(infoId);
    }

    /**
     * 用于查看点赞数量信息
     * @param infoId
     * @return
     */
    @GetMapping("/count")
    public Result count(@RequestParam String infoId){
        return likeService.count(infoId);
    }


    /**
     * 用于查看是否已经点赞
     * @param infoId
     * @return
     */
    @GetMapping("/status")
    public Result status(@RequestParam String infoId){
        return likeService.status(infoId);
    }

}